package com.ymatou.iapi.optrade.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.optrade.parameter.req.SyncOrderIdCardInfoReq;
import com.ymatou.iapi.optrade.service.SyncIdCardInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.sharding.db.sharding.model.OrderPo;
import com.ymttest.database.sharding.db.sqlwapper.OrderShardingWapper;

/**
*身份证信息同步
*FreeMaker Template自动生成代码
*/
@TestSuite
@Ignore
public class Ts_SyncIdCardInfo {
	private static SyncOrderIdCardInfoReq syncidcardinfo;
	private static SyncIdCardInfoCall syncidcardinfoCall;
	
	private static OrderShardingWapper orderShardingWapper = new OrderShardingWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("身份证信息同步");
	}

	@Before
	public void caseUp() {
		syncidcardinfo = new SyncOrderIdCardInfoReq();
		syncidcardinfoCall = new SyncIdCardInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(syncidcardinfoCall.getOpurl());
		orderShardingWapper.activeDeadCommunicationsLink(orderShardingWapper);
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	/**
	 *  注意依赖的   idcardquery.iapi.ymatou.com 是否起好了
	 */
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_SyncIdCardInfo_001() {
		Logger.start(true, "身份证验证信息同步成功");
		try {
			syncidcardinfo.setBuyerId(25552812);
			syncidcardinfo.setMainOrderId(1800062812L);
			syncidcardinfo.setName("王五");

			syncidcardinfoCall.setData(syncidcardinfo);
			syncidcardinfoCall.callService();

			Logger.verifyEquals("ok", syncidcardinfoCall.getReturnData(),
					"验证Code");

			OrderPo actualOrder1 = orderShardingWapper
					.selectOrderbyMainOrderId(syncidcardinfo.getMainOrderId())
					.get(0);

			Logger.comment("校验用户是否已经上传身份证");

			Logger.verifyEquals(true, actualOrder1.getUploadedIdcard(),
					"验证数据库UploadedIdcard");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SyncIdCardInfo_002() {
		Logger.start(false, "身份证用户名为空,验证失败");
		try {
			syncidcardinfo.setBuyerId(4085);

			syncidcardinfoCall.setData(syncidcardinfo);
			syncidcardinfoCall.callService();

			//Logger.verifyEquals("fail", syncidcardinfoCall.getMsg(), "验证Msg");
			Logger.verifyEquals("fail", syncidcardinfoCall.getReturnData(),
					"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_SyncIdCardInfo_003() {
		Logger.start(false, "用户ID为空,验证失败");
		try {

			syncidcardinfo.setName("巴巴");

			syncidcardinfoCall.setData(syncidcardinfo);
			syncidcardinfoCall.callService();

			Logger.verifyEquals("fail", syncidcardinfoCall.getReturnData(),
					"验证Code");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}